package thread;

/**
 * @author Dianzhi Han
 * @version 1.0
 * @description: 线程的一些属性方法
 * @date 2022/10/28 1:10
 */
public class ThreadAttr {
    public static void main(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName() + "我还活着~");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                System.out.println(Thread.currentThread().getName() + "I'm going to die....");
            }
        },"测试线程");
        // -------------------------以下为主线程
        System.out.println(Thread.currentThread().getName() + ": ID" + thread.getId());
        System.out.println("状态 : " + Thread.currentThread().getState());
        System.out.println("优先级 : " + Thread.currentThread().getPriority());
        System.out.println("后台线程 ？ " + Thread.currentThread().isDaemon());
        System.out.println("是否存活 ？ " + Thread.currentThread().isAlive());
        System.out.println("是否存活 ？ " + thread.isAlive());
        thread.start();
    }
}